home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / NET / ServerSocket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  2.3 KB  |  81 lines

  1. package java.net;
  2.  
  3. import java.io.FileDescriptor;
  4. import java.io.IOException;
  5.  
  6. public final class ServerSocket {
  7.    SocketImpl impl;
  8.    private static SocketImplFactory factory;
  9.  
  10.    ServerSocket() throws IOException {
  11.       this.impl = (SocketImpl)(factory != null ? factory.createSocketImpl() : new PlainSocketImpl());
  12.    }
  13.  
  14.    public ServerSocket(int var1) throws IOException {
  15.       this(var1, 50);
  16.    }
  17.  
  18.    public ServerSocket(int var1, int var2) throws IOException {
  19.       this();
  20.       SecurityManager var3 = System.getSecurityManager();
  21.       if (var3 != null) {
  22.          var3.checkListen(var1);
  23.       }
  24.  
  25.       this.impl.create(true);
  26.       this.impl.bind(InetAddress.anyLocalAddress, var1);
  27.       this.impl.listen(var2);
  28.    }
  29.  
  30.    public InetAddress getInetAddress() {
  31.       return this.impl.getInetAddress();
  32.    }
  33.  
  34.    public int getLocalPort() {
  35.       return this.impl.getLocalPort();
  36.    }
  37.  
  38.    public Socket accept() throws IOException {
  39.       Socket var1 = new Socket();
  40.  
  41.       try {
  42.          var1.impl.address = new InetAddress();
  43.          var1.impl.fd = new FileDescriptor();
  44.          this.impl.accept(var1.impl);
  45.          SecurityManager var2 = System.getSecurityManager();
  46.          if (var2 != null) {
  47.             var2.checkAccept(var1.impl.getInetAddress().getHostName(), var1.impl.getPort());
  48.          }
  49.  
  50.          return var1;
  51.       } catch (IOException var3) {
  52.          var1.close();
  53.          throw var3;
  54.       } catch (SecurityException var4) {
  55.          var1.close();
  56.          throw var4;
  57.       }
  58.    }
  59.  
  60.    public void close() throws IOException {
  61.       this.impl.close();
  62.    }
  63.  
  64.    public String toString() {
  65.       return "ServerSocket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
  66.    }
  67.  
  68.    public static synchronized void setSocketFactory(SocketImplFactory var0) throws IOException {
  69.       if (factory != null) {
  70.          throw new SocketException("factory already defined");
  71.       } else {
  72.          SecurityManager var1 = System.getSecurityManager();
  73.          if (var1 != null) {
  74.             var1.checkSetFactory();
  75.          }
  76.  
  77.          factory = var0;
  78.       }
  79.    }
  80. }
  81.